<template>
	<view>
		<!-- 	<view class="" @click="openCameras">
			扫码
		</view> -->
		<view class="sectionview flex-center" v-if="show" @click="show=false">
			<mumu-oneCode @success='handlerSuccess' definition :readers='["code_128_reader"]'></mumu-oneCode>
		</view>
	</view>
</template>

<script setup>
	// import MumuOneCode from '@/uni_modules/mumu-oneCode/components/mumu-oneCode/mumu-oneCode.vue'
	import {
		onLoad,
		onShow,
		onUnload,
			onBackPress
	} from "@dcloudio/uni-app";
	import {
		ref
	} from "vue";
	import {
		showToast
	} from "@/utils/toast";
	const show = ref(false)
	onShow(() => {
console.log("onLoad" )
		openCameras();
	});
onUnload(() => {
console.log("onHide" )
		show.value = false;
	});
	onBackPress(() => {
	console.log("onBackPress" )
			openCameras();
		});
	function openCameras() {
		console.log("openCameras" )
		if (origin.indexOf('https') === -1) {
			showToast('请在 https 环境中使用摄像头组件。')
			return
		}
		show.value = true;
	}

	function handlerSuccess(code) {
		// $emit('change', code)
		console.log("code=" + code)
		uni.$emit('scanResult', code); //返回需要获取到扫码结果的页面,提交数据
		uni.navigateBack()
		show.value = false
	}
</script>

<style lang="scss">
	.flex-center {
		display: flex;
		align-items: center;
		justify-content: center;
	}

	.sectionview {
		position: fixed;
		top: 0;
		left: 0rpx;
		width: 100%;
		height: 100vh;
		z-index: 99;
	}
</style>